Sign In
Authentication
Sign In
Authenticate a user and receive JWT tokens for API access
POST
Sign In
Overview
The sign-in endpoint authenticates existing users and returns JWT access and refresh tokens. Users can authenticate using their email and password.Endpoint
Request Body
User’s email address registered in the system.
User’s password.
Response
JWT access token for authenticating subsequent API requests. This is a short-lived token.
JWT refresh token used to obtain new access tokens when they expire.
Complete user object containing authenticated user’s information.
Unique identifier for the user.
User’s username.
User’s email address.
User’s first name.
User’s last name.
User’s phone number.
URL to user’s avatar image (if uploaded).
Example Request
cURL
Python
JavaScript
Example Response
200 OK
Error Responses
400 Bad Request - Invalid Password
400 Bad Request - Missing Fields
404 Not Found - User Does Not Exist
500 Internal Server Error
Implementation Details
The sign-in endpoint is implemented inapps/users/views.py:21-44. Here’s the authentication flow:
- User Lookup: Retrieves user by email using
get_object_or_404() - Password Verification: Validates password using Django’s
check_password()method - Token Generation: Creates JWT tokens using
RefreshToken.for_user(user) - User Serialization: Returns complete user data via
UsersSerializer - Response: Returns tokens and user object on success
Code Reference
Fromapps/users/views.py:21-44:
Using the Access Token
Once you receive the access token, include it in the Authorization header for authenticated requests:cURL
Python
Notes
- This endpoint does not require authentication (
@permission_classes([AllowAny])) - Authentication is performed using email (not username)
- Passwords are never returned in the response
- The access token has a limited lifetime and should be refreshed using the refresh token
- Failed login attempts return specific error messages to help identify the issue
